package org.springframework.samples.mvc.convert;

import org.apache.commons.lang3.time.DateUtils;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;

import java.util.Date;

/**
 * 自定义日期转换
 * @author yg.huang
 * @version v1.0
 *          DATE  2016/11/24
 */
@Component("customDateConverter")
public class CustomDateConverter implements Converter<String,Date>{

    @Override
    public Date convert(String source) {

        try {
            Date result= DateUtils.parseDate(source,"yyyy-MM-dd","yyyy-MM-dd HH:mm:ss");
            return  result;
        } catch (ParseException e) {
            return null;
        }

    }

}
